home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_6_6.arc / LISTING.3 < prev    next >
Text File  |  1988-08-30  |  1KB  |  43 lines

  1.   1  /*
  2.   2   * daemon.c     -----   The background process that waits for events to happen
  3.   3   *                      and performs some task based on that event.  Most
  4.   4   *                      of the time, a daemon's action goes usually unnoticed 
  5.   5   *                      by users.
  6.   6   */
  7.   7  
  8.   8  #include <sys/signal.h>
  9.   9  #include <fcntl.h>
  10.  10  #include <stdio.h>
  11.  11  #include "local.h"
  12.  12  
  13.  13  /*
  14.  14   *  This is not the most complete method of creating a Unix daemon.
  15.  15   *  Please see the paper by Dave Lennert in the Usenix ;login: newsletter
  16.  16   *  dated July/August 1987 called "How To Write a Unix Daemon".
  17.  17   */
  18.  18  
  19.  19  main(argc,argv)
  20.  20  char **argv;
  21.  21  {
  22.  22      int fd;
  23.  23      PACKET test;
  24.  24  
  25.  25      signal(SIGINT, SIG_IGN);    /* Only kill self when client says so */
  26.  26  
  27.  27  
  28.  28  /*  Now open the FIFO for reading */
  29.  29  
  30.  30      if ( (fd = open(PIPE, O_RDONLY))  ==  -1 )
  31.  31          fprintf(stderr, "Cannot open PIPE\n"), exit(1);
  32.  32  
  33.  33      while(1)
  34.  34      {
  35.  35          read(fd, &test, sizeof test);           /* Read client via FIFO*/
  36.  36  
  37.  37          if ( !strcmp(test.string, "Done") )
  38.  38              printf("Byebye from Daemon\n"), exit(1);
  39.  39          
  40.  40          printf("PID: %d - string: [%s]\n", test.pid, test.string);
  41.  41      }
  42.  42  }
  43.